package app.fugema.shop.main.goods.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.base.common.utils.DensityUtil;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseViewHolder;
import com.base.common.view.widget.banner.BannerImageLoader;
import com.base.common.view.widget.imageView.GlideImageView;
import com.base.common.view.widget.imageView.ImageLoaderUtils;
import com.base.common.view.widget.imageView.ShapeType;
import app.fugema.shop.R;
import app.fugema.shop.databinding.ShopBannerBinding;
import app.fugema.shop.main.goods.model.ShopBannerData;
import app.fugema.shop.main.goods.model.VShopResult;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;


public class ShopBannerItemType extends BaseItemMultiType<ShopBannerData, ShopBannerBinding>
{

    @Override
    public int getLayoutId() {
        return R.layout.shop_banner;
    }

    @Override
    public int getItemViewType() {
        return TYPE_HEAD;
    }

    @Override
    public boolean isFullSpanType() {
        return true;
    }

    @Override
    public void onCreateViewHolder(ShopBannerBinding binding, BaseViewHolder viewHolder) {
        super.onCreateViewHolder(binding, viewHolder);
        binding.banner.setIndicatorGravity(BannerConfig.CENTER);
        LinearLayout circleIndicator = binding.banner.findViewById(R.id.circleIndicator);
        if (circleIndicator != null) {
            circleIndicator.setPadding(DensityUtil.getDimens(R.dimen.dp_32), 0, 0, DensityUtil.getDimens(R.dimen.dp_10));
        }

    }

    @Override
    public void onBindViewHolder(ShopBannerBinding binding, int position, ShopBannerData bean)
    {
        super.onBindViewHolder(binding, position, bean);
        binding.banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                //VShopResult.SlideImgsBean dataBean = bean.getData().get(position);
                //
                /*
                switch (dataBean.getLinkType())
                {
                    case 1:
                        GoodsDetailActivity.start(binding.banner.getContext(), dataBean.getTargetId());
                        break;
                }
                */
            }
        });

        binding.banner.setImages(bean.getData()).setImageLoader(new BannerImageLoader() {

            @Override
            public void displayImage(Context context, Object path, GlideImageView imageView) {
                VShopResult.SlideImgsBean bannerInfo = (VShopResult.SlideImgsBean) path;
                ImageLoaderUtils.loadImage(imageView, bannerInfo.getImageUrl());
            }

            int dp16 = DensityUtil.getDimens(R.dimen.dp_15);

            @Override
            public GlideImageView createImageView(Context context) {
                GlideImageView glideImageView = super.createImageView(context);
                glideImageView.setShapeType(ShapeType.RECTANGLE);
                //glideImageView.setRadius(DensityUtil.getDimens(R.dimen.dp_10));
                glideImageView.setScaleType(ImageView.ScaleType.FIT_XY);
                //dp16
                glideImageView.setPadding(0, 0, 0, 0);
                return glideImageView;
            }


        }).setDelayTime(3000).start();


    }


}
